package com.droidexchange.custom;

import java.text.SimpleDateFormat;
import net.sf.stackwrap4j.entities.Question;
import net.sf.stackwrap4j.entities.User;
import net.sf.stackwrap4j.utils.StackUtils;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.droidexchange.R;
import com.droidexchange.main.DeMajorPost;

public class AnswerTabMain extends RelativeLayout
{
	public AnswerTabMain(Context context)
	{
		this(context, null);
	}

	public AnswerTabMain(Context context, AttributeSet attrs)
	{
		this(context, attrs, 0);
	}

	public AnswerTabMain(Context context, AttributeSet attrs, int defStyle)
	{
		super(context, attrs, defStyle);
		((Activity) getContext()).getLayoutInflater().inflate(R.layout.answer_tab_panel, this, true);
	}

	public void setViewContents(DeMajorPost post)
	{
		User user = post.majorPost.getOwner();
		try
		{
			if (user != null)
			{
//				ImageView imgGravatar = (ImageView) findViewById(R.id.img_gravatar);
//				URL urlGravatar = new URL("http://www.gravatar.com/avatar/" + user.getEmailHash() + "?s="
//						+ imgGravatar.getWidth() + "&d=identicon&r=PG");
//				Bitmap bmpGravatar = BitmapFactory.decodeStream(urlGravatar.openStream());
//				imgGravatar.setImageBitmap(bmpGravatar);

				TextView txtName = (TextView) findViewById(R.id.name);
				txtName.setText(user.getDisplayName());

				TextView txtreputation = (TextView) findViewById(R.id.reputation);
				txtreputation.setText(Integer.toString(user.getReputation()));
			}

			TextView txtAction = (TextView) findViewById(R.id.action);
			txtAction.setText(post.majorPost instanceof Question ? "asked" : "answered");

			SimpleDateFormat sdf = new SimpleDateFormat();
			TextView txtDateTime = (TextView) findViewById(R.id.date_time);
			txtDateTime.setText(StackUtils.formatElapsedTime(post.majorPost.getCreationDate()));
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
